﻿using System;
using System.Collections.Generic;

using AjaxAvailableUserControls.Library.Logic;

namespace AjaxAvailableUserControls.Application.AjaxUserControls
{
    /// <summary>
    /// User control to demonstate some benefits of usage AjaxAvailableUserControl 
    /// </summary>
    public partial class DemoUserControl : AjaxAvailableUserControl
    {
        #region demo methods here
        public AjaxResponse MyDemoMethod1(string arg1, string arg2, int arg3, bool arg4)
        {
            AjaxResponse result = new AjaxResponse
            {
                AdditionalSettings = String.Format("This is response to callback with parameters {0}/{1}/{2}/{3} from server side", arg1, arg2, arg3, arg4),
                CurrentPage = 0,
                Records = new List<object>() 
                {
                    new 
                    {
                        Date = DateTime.Now,
                        Data = int.MinValue
                    }
                },
                TotalRecords = 1,
                TotalPages = 1
            };

            return result;
        }

        public AjaxResponse MyDemoMethod2(int arg1, bool arg2)
        {
            AjaxResponse result = new AjaxResponse
            {
                AdditionalSettings = String.Format("This is response to callback with parameters {0}/{1} from server side", arg1, arg2),
                Records = new List<object>() 
                {
                    new 
                    {
                        Date = DateTime.Now,
                        Data = int.MinValue,
                        OtherProperties = new List<object>{1, 2, 3}
                    }
                }
            };

            return result;
        }

        public AjaxResponse MyDemoMethod3()
        {
            CustomAjaxResponse result = new CustomAjaxResponse
            {
                AdditionalSettings = "This is response to callback without any parameters from server side",
                Records = new List<object>() 
                {
                    new 
                    {
                        Date = DateTime.Now,
                        Data = int.MinValue,
                        OtherProperties = new List<object>{1, 2, 3}
                    }
                },
                MyCustomValue = 100
            };

            return result;
        } 

        #endregion

        #region there is custom responce definition to expand response usage boundaries
        public class CustomAjaxResponse : AjaxResponse
        {
            public int MyCustomValue { get; set; }
        } 
        #endregion

    }
}